<template>
  <div class="scroll-content">
    <p class="description">当前路由：{{ route.fullPath }}</p>
    <a-typography>
      <a-typography-title class="headline">
        <span class="accent">Electron-AntDV桌面软件Demo</span>
      </a-typography-title>

      <a-typography-title :level="4">系统简介</a-typography-title>

      <p>
        Electron-AntDV开源项目是基于Electron-Egg 桌面软件开发框架和Ant-Design-Vue 前端组件的应用Demo软件模板。
      </p>
      <p>
        本项目对Electron能力进行了实例化的展示，并附上了简单的说明，方便他同学快速理解Electron以及Electron-Egg框架

      </p>
      <a-typography-title :level="4">开发文档 </a-typography-title>
      <a-typography-paragraph>
        
        <blockquote>
          <a-typography-paragraph :copyable="{ text: 'https://www.electronjs.org/zh/docs/latest/' }">
            Electron官方开发文档 https://www.electronjs.org/zh/docs/latest/
          </a-typography-paragraph>
        </blockquote>
        <blockquote>
          <a-typography-paragraph :copyable="{ text: 'https://www.kaka996.com/' }">
            Electron-Egg框架开发文档 https://www.kaka996.com/
          </a-typography-paragraph>
        </blockquote>
      </a-typography-paragraph>      

  
      

    </a-typography>
  </div>
</template>

<script setup>
import { ipcApiRoute } from "@/api/main";
import { ipc, isEE } from "@/utils/ipcRenderer";
import { message } from "ant-design-vue";

import { onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
const route = useRoute();
const router = useRouter();

const machineId = ref("-");
const serveState = ref("-");
const localStorage = ref("LocalStorage: -");
const records = ref([]);
const latest = ref({ version: "1.0.1", update: "2024-05-01" });
const user1 = ref({ name: "老吴", age: 24, sex: "男" });
const user2 = ref({ name: "小黄", age: 18, sex: "女" });
const data_dir = ref("242");

message.config({
  top: "120px",
  duration: 1,
  maxCount: 4,
});

onMounted(() => {
  init();
});

const init = () => {
  // checkHttpServer();
  // readMachineId();
};
const readLocalstorage = () => {
  localStorage.value = storage.getAll();
};
const clearLocalstorage = () => {
  message.success("清理本地缓存");
  storage.clear(false);
  localStorage.value = storage.getAll();
};
const setLocalstorage = () => {
  storage.set("demo", { name: "张三", age: 34, sex: "男" });
  localStorage.value = storage.getAll();
};

const checkHttpServer = () => {
  if (isEE) {
    serveState.value = "-";
    ipc.invoke(ipcApiRoute.checkHttpServer, {}).then((r) => {
      if (r.enable) {
        setTimeout(() => {
          serveState.value = r.server;
          storage.set("config", r);
        }, 200);
      } else {
        serveState.value = "未开启";
      }
    });
  } else {
    serveState.value = "浏览器中不能读取";
    message.error("部分功能需要EE环境支持");
  }
};

const readMachineId = () => {
  if (isEE) {
    machineId.value = "-";
    ipc.invoke(ipcApiRoute.getMachineId).then((res) => {
      machineId.value = res;
      storage.set("config", { machineid: res });
    });
  } else {
    serveState.value = machineId.value = "浏览器中不能读取";
    message.error("部分功能需要EE环境支持");
  }
};

const addRecord = () => {
  const params = {
    action: "add",
    info: {
      name: user1.value.name,
      age: user1.value.age,
      sex: user1.value.sex,
    },
  };
  if (parseInt(user1.age).length == 0) {
    message.info("请填写年龄", 2);
    return;
  }
  if (isEE) {
    ipc.invoke(ipcApiRoute.jsondbOperation, params).then((res) => {
      console.log("icp res:", res);
      records.value = res.all_list;
      message.info("返回成功！", 1);
    });
  } else {
    message.error("开发模式无法操作数据库");
  }
};
const delRecord = () => {
  if (
    user1.value.name == "" ||
    user1.value.name == null ||
    user1.value.name === ""
  ) {
    message.info("请填写姓名", 2);
    return;
  }
  const params = {
    action: "del",
    info: {
      key: user1.value.name,
    },
  };
  if (isEE) {
    ipc.invoke(ipcApiRoute.jsondbOperation, params).then((res) => {
      console.log("icp res:", res);
      records.value = res.all_list;
      message.info("删除完成！", 1);
    });
  } else {
    message.error("开发模式无法操作数据库");
  }
};
const dbOperation = (ac) => {
  const info = {
    name: user1.value.name,
    age: user1.value.age,
    sex: user1.value.sex,
  };

  if (isEE) {
    ipc
      .invoke(ipcApiRoute.jsondbOperation, { action: ac, info: info })
      .then((res) => {
        console.log("icp res:", res);
        records.value = res.all_list;
        message.info("返回成功！", 1);
      });
  } else {
    message.error("开发模式无法操作数据库");
  }
};

const readConfig = () => {
  const params = {
    action: "getDataDir",
  };
  if (isEE) {
    ipc.invoke(ipcApiRoute.jsondbOperation, params).then((res) => {
      console.log("res:", res);
      records.value = res.all_list;
    });
  } else {
    message.error("开发模式无法操作数据库");
  }
};

const readSystem = () => {
  const params = {
    action: "readSetting",
    info: { key: "machineCode" },
  };
  if (isEE) {
    ipc.invoke(ipcApiRoute.jsondbOperation, params).then((res) => {
      console.log("res:", res);
      records.value = res.all_list;
    });
  } 
};
</script>

<style lang="less" scoped>
.scroll-content {
  height: 100%;
  margin-right: 5px;
  font-weight: 400;
  padding: 10px 30px 30px 30px;
  box-sizing: border-box;
  overflow: auto;
}

@media (min-width: 960px) and (max-width: 1299px) {
  .scroll-content {
    padding: 20px 40px 30px 40px;
  }
}

@media (min-width: 1300px) {
  .scroll-content {
    padding: 30px 50px 30px 50px;
  }
}

.scroll-content::-webkit-scrollbar-track {
  background-color: #f1f1f1;
  border-radius: 10px;
}

.scroll-content::-webkit-scrollbar-thumb {
  background-color: #888;
  border-radius: 10px;
  border: 2px solid #ffffff;
}

.scroll-content::-webkit-scrollbar {
  width: 10px;
}

html:not(.dark) .accent,
.dark .headline {
  background: -webkit-linear-gradient(315deg, #42d392 25%, #647eff);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sysinfo {
  max-width: 600px;
  width: 50%;
  color: #00770b;
  line-height: 1.4;
  float: right;
  padding: 10px;
  word-wrap: break-word;
}

p {
  line-height: 1.8;
  margin-top: 10px;
}

.headline {
  font-size: 32px;
  line-height: 1.9;
  font-weight: bold;
  letter-spacing: -1.5px;
  margin: 0px auto;
}

.subtitle {
  line-height: 1.5;
  color: var(--vt-c-text-2);
  transition: color 0.5s;
  font-size: 22px;
  margin: 44px auto 16px;
}

.actions a,
.actions .btn {
  font-size: 16px;
  line-height: 1;
  display: inline-block;
  background-color: var(--vt-c-bg-mute);
  padding: 6px 16px;

  font-weight: 500;
  border-radius: 30px;
  transition:
    background-color 0.5s,
    color 0.5s;
  text-decoration: none;
}

.actions .btn {
  margin: 0px 8px 8px 0px;
  text-align: center;
  color: var(--vt-c-text-code);
  border: 0px;
  cursor: pointer;
  background: -webkit-linear-gradient(315deg, #42d392 25%, #647eff);
}

.actions .btn:hover {
  background-color: var(--vt-c-gray-light-4);
  transition-duration: 0.2s;
}
</style>
